package cn.wusifx.zabbix.request.builder.application;

import cn.wusifx.zabbix.request.BaseRequest;
import cn.wusifx.zabbix.request.builder.RequestBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * https://www.zabbix.com/documentation/4.0/manual/api/reference/application/massadd
 */
public class ApplicationMassaddRequestBuilder extends RequestBuilder<Map<String,Object>> {
    private List<Map<String,Object>> applications;
    private List<Map<String,Object>> items;
    public ApplicationMassaddRequestBuilder(String auth) {
        super("application.massadd", auth);
        baseRequest.setParams(new HashMap<>());
    }

    public ApplicationMassaddRequestBuilder(Long id, String auth) {
        super("application.massadd", id, auth);
        baseRequest.setParams(new HashMap<>());
    }

    public ApplicationMassaddRequestBuilder setParam(String key, Object value){
        baseRequest.getParams().put(key,value);
        return this;
    }
    public ApplicationMassaddRequestBuilder setParams(Map<String,Object> params){
        baseRequest.getParams().putAll(params);
        return this;
    }

    public List<Map<String, Object>> getApplications() {
        return applications;
    }

    public ApplicationMassaddRequestBuilder setApplications(List<Map<String, Object>> applications) {
        this.applications = applications;
        return this;
    }
    public ApplicationMassaddRequestBuilder setApplication(Map<String, Object> application) {
        if(this.applications == null){
            this.applications = new ArrayList<>();
        }
        this.applications.add(application);
        return this;
    }
    public ApplicationMassaddRequestBuilder setApplicationId(String applicationId) {
        if(this.applications == null){
            this.applications = new ArrayList<>();
        }
        Map<String,Object> application = new HashMap<>();
        application.put("applicationid",applicationId);
        this.applications.add(application);
        return this;
    }

    public List<Map<String, Object>> getItems() {
        return items;
    }

    public ApplicationMassaddRequestBuilder setItems(List<Map<String, Object>> items) {
        this.items = items;
        return this;
    }

    public ApplicationMassaddRequestBuilder setItem(Map<String, Object> item) {
        if(this.items == null){
            this.items = new ArrayList<>();
        }
        this.items.add(item);
        return this;
    }

    @Override
    public BaseRequest<Map<String, Object>> builder() {
        if(applications != null){
            baseRequest.getParams().put("applications",applications);
        }
        if(items != null){
            baseRequest.getParams().put("items",items);
        }
        return baseRequest;
    }
}
